package com.lemon.smartsafetynew.ui.activity.record;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.entity.record.MetalVo;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 冶金详情
 * Created by JiangAn on 2018/5/24.
 */

public class RecordMetalDetailActivity extends SwipeBackActivity {

    @Bind(R.id.iv_return)
    ImageView ivReturn;
    @Bind(R.id.tv_code_and_name)
    TextView tvCodeAndName;
    @Bind(R.id.tv_material_type)
    TextView tvMaterialType;
    @Bind(R.id.tv_metal_main_product)
    TextView tvMetalMainProduct;
    @Bind(R.id.tv_is_carrier_move)
    TextView tvIsCarrierMove;
    @Bind(R.id.tv_is_metaling)
    TextView tvIsMetaling;
    @Bind(R.id.tv_main_product_method)
    TextView tvMainProductMethod;
    @Bind(R.id.tv_heating_type)
    TextView tvHeatingType;
    @Bind(R.id.tv_metal_year_product)
    TextView tvMetalYearProduct;
    @Bind(R.id.tv_sence_users)
    TextView tvSenceUsers;
    @Bind(R.id.tv_space_remark)
    TextView tvSpaceRemark;

    private static MeCompanyVo companyVo;
    private static MetalVo metalVo;

    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.record_material));
    }

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {

            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }

            if (bundle.containsKey(KeyConstants.KEY_RECORD_METAL_VO)) {
                metalVo = (MetalVo) bundle.getSerializable(KeyConstants.KEY_RECORD_METAL_VO);
            }
        }
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(RecordMetalDetailActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_record_metal_detail;
    }

    @Override
    protected void initViews() {
        super.initViews();

        if (companyVo.getIfShowReturn()) {
            ivReturn.setVisibility(View.VISIBLE);
        } else {
            ivReturn.setVisibility(View.INVISIBLE);
        }

        initMetalView();
    }

    /**
     * 冶金信息详情页初始化
     */
    private void initMetalView() {
        tvCodeAndName.setText(CommonUtil.avoidNullString(metalVo.getCode_name()));
        tvMaterialType.setText(CommonUtil.avoidNullString(metalVo.getTypeName()));
        tvMetalMainProduct.setText(CommonUtil.avoidNullString(metalVo.getMain_product()));
        tvIsCarrierMove.setText(CommonUtil.avoidNullString(metalVo.getIsMove()));
        tvIsMetaling.setText(CommonUtil.avoidNullString(metalVo.getIsMelting()));
        tvMainProductMethod.setText(CommonUtil.avoidNullString(metalVo.getMain_product_process()));
        tvHeatingType.setText(CommonUtil.avoidNullString(metalVo.getHeating()));
        tvMetalYearProduct.setText(CommonUtil.avoidNullString(metalVo.getAnnual_output()));
        tvSenceUsers.setText(CommonUtil.avoidNullString(metalVo.getPeople_count()));
        tvSpaceRemark.setText(CommonUtil.avoidNullString(metalVo.getRemark()));
    }

    @Override
    protected void initListener() {
        super.initListener();
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppManager.getAppManager().finishActivity(RecordMetalDetailActivity.this);
                AppManager.getAppManager().finishActivity(RecordMetalActivity.class);
            }
        });
    }

}


